import {
  profitCountTable,

  profitCountTableForXBeauty,
} from '../../services/channel/api';


export default {
  namespace: 'grossProfit',

  state: {

    loading: true,

    grossProfitData: {
      list: [],
      pagination:{}
    },

  },

  effects: {

    *fetchProfitCountTable({payload, callback}, {call, put}) {
      const response = yield call(profitCountTable, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {
            grossProfitData: {
              list: response.data.list,
              pagination:{
                current: response.data.currentPage,
                total: response.data.totalCount,
              }
            },
          },
        });
        if (callback) callback();
      }
    },

    //想美
    *fetchProfitCountTableForXBeauty({payload, callback}, {call, put}) {
      const response = yield call(profitCountTableForXBeauty, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {
            grossProfitData: {
              list: response.data.list,
              pagination:{
                current: response.data.currentPage,
                total: response.data.totalCount,
              }
            },
          },
        });
        if (callback) callback();
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },

};
